package com.dxb.test.exam;

import java.util.Enumeration;
import java.util.Stack;

/**
 * ClassName：com.dxb.test.exam.ArrayCompute <br>
 * Description：TODO <br>
 *
 * @author 戴晓波 <br>
 * Date 2021/12/21/021 10:48 <br>
 * @version v1.0 <br>
 */
public class ArrayCompute {
    public static Stack<Boolean> stack = new Stack<Boolean>();
    private static int max = Integer.MIN_VALUE;
    private static int index = 0;


    public static void main(String[] args) {
        int[] arr1 = {1, 2, 3, 4, 5};
        int[] arr2 = {1, 2, 3, 4, 5};
        f(arr1, arr2, 0);
        System.out.println("max:" + max);
    }

    private static void f(int[] arr1, int[] arr2, int cur) {
        if (cur == arr2.length - 1) {
            System.out.println(++index + ":" + stack);
            Enumeration<Boolean> elements = stack.elements();
            int i = 0, j = arr2.length - 1;
            int k = 0;
            int sum = 0;
            while (elements.hasMoreElements()) {
                sum += arr1[k++] * (elements.nextElement() ? arr2[i++] : arr2[j--]);
            }
            System.out.println(i == j);
            sum += arr1[k] * arr2[i];
            System.out.println("sum:" + sum);
            max = Math.max(max, sum);
            return;
        }
        boolean[] sh = {true, false};
        for (boolean b : sh) {
            stack.add(b);
            f(arr1, arr2, cur + 1);
            stack.pop();
        }
    }
}
